from PyQt5.QtWidgets import *
import sys
 
class QLineEditEchoMode(QDialog):
    def __init__(self):
        super(QLineEditEchoMode, self).__init__()
        self.initUI()
 
    def initUI(self):
        self.setWindowTitle('文件输入框的回显模式')
        self.resize(400,300)
        #表单布局
        formLayout=QFormLayout()
        #创建编辑框
        normalLineEdit=QLineEdit()
        noEchoLineEdit = QLineEdit()
        passwordLineEdit = QLineEdit()
        passwordEchoOnEditLineEdit = QLineEdit()
        #放入表单布局中
        formLayout.addRow('Normal',normalLineEdit)
        formLayout.addRow('NoEcho',noEchoLineEdit)
        formLayout.addRow('Password',passwordLineEdit)
        formLayout.addRow('PasswordEchoOnEdit',passwordEchoOnEditLineEdit)
        #placeholdertext(没输入时文本框里默认显示的灰色字体)
        normalLineEdit.setPlaceholderText('Normal')
        noEchoLineEdit.setPlaceholderText('NoEcho')
        passwordLineEdit.setPlaceholderText('Password')
        passwordEchoOnEditLineEdit.setPlaceholderText('PasswordEchoOnEdit')
        #设置文本框回显模式
        normalLineEdit.setEchoMode(QLineEdit.Normal)
        noEchoLineEdit.setEchoMode(QLineEdit.NoEcho)
        passwordLineEdit.setEchoMode(QLineEdit.Password)
        passwordEchoOnEditLineEdit.setEchoMode(QLineEdit.PasswordEchoOnEdit)
 
        self.setLayout(formLayout)
        return
 
if __name__=='__main__':
    app=QApplication(sys.argv)
    main=QLineEditEchoMode()
    main.show()
    sys.exit(app.exec_())
 
 
